﻿
package com.victim.snake.player
{
	import com.victim.snake.user.ProcessMsg;
	
	import flash.utils.ByteArray;

	//房间业务类
	public class PlayerBo{

		public function PlayerBo():void{
			
		}
		
		//设置玩家是否准备
		static public function setReadyOrUnReady(player:Player,bol:Boolean):void{
			player.setIsReady(bol);
		}
		
		//设置玩家是否自动准备
		static public function setAutoReady(player:Player,bol:Boolean):void{
			player.setAutoReady(bol);
		}
		
		//返回用户是否准备
		static public function getIsReady(player:Player):Boolean{
			return player.getIsReady();
		}
		

		
		
		static public function setSnakeStyle(player:Player,snakeStyle:String):void{
			player.setSnakeStyle(snakeStyle);
		}
		
		//向服务器发送玩家准备消息 0：不准备  1：准备  消息格式(用户id+准备或不准备代码)
		static public function sendReadyOrUnReadyMsg(player:Player):void{						
			if(PlayerBo.getIsReady(player)){	//如果玩家以准备，发送取消准备消息
				ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(17,player.getUid()+";0"));
			}else{	//如果玩家末准备，发送准备消息
				ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(17,player.getUid()+";1"));
			}
		}
		
		//向服务器发送玩家设置自动准备消息 0：不自动准备  1：自动准备  消息格式(用户id+准备或不准备代码)
		static public function sendAutoReadyMsg(player:Player,bol:Boolean):void{						
			if(bol){
				ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(21,player.getUid()+";1"));
				//如果玩家末准备,发送准备消息
				if(!player.getIsReady()){
					ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(17,player.getUid()+";1"));
				}
			}else{
				ProcessMsg.socketSend(ProcessMsg.generateUTF8Msg(21,player.getUid()+";0"));
			}			
		}

	}

}